import { createRouter, createWebHistory } from 'vue-router'
import routerGuard from './router-guard.js'
import Layout from '@/layout/index.vue'
import Home from '@/views/Home/index.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        {
          path: '/',
          redirect: '/home'
        },
        {
          path: '/home',
          name: 'home',
          component: Home,
          meta: {
            title: '首页'
          }
        },
        {
          path: '/article',
          redirect: '/article/list',
          children: [
            {
              path: '/article/list',
              name: 'article-list',
              component: () => import('@/views/article-list/index.vue')
            },
            {
              path: '/article/read/:id',
              name: 'article-read',
              component: () => import('@/views/article-read/index.vue')
            },
            {
              path: '/article/edit/:id',
              name: 'article-edit',
              component: () => import('@/views/article-edit/index.vue')
            },
            {
              path: '/article/create',
              name: 'article-create',
              component: () => import('@/views/article-edit/index.vue')
            }
          ]
        },
        {
          path: '/chart',
          name: 'chart',
          component: () => import('@/views/chart/index.vue'),
          meta: {
            title: '图表'
          }
        },
        {
          path: '/dnd',
          name: 'dnd',
          component: () => import('@/views/dnd/index.vue'),
          meta: {
            title: '拖拽'
          }
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/Login/index.vue')
    },
    {
      path: '/test',
      name: 'test',
      component: () => import('@/views/test/index.vue')
    }
  ]
})
routerGuard(router)

export default router
